import time
import unittest,threading
from threadpool import ThreadPool, makeRequests


def test_task(name):
    print("{0}:{1}\n".format(threading.current_thread().name,name))
    time.sleep(10)


class TestTask(unittest.TestCase):
    def test01(self):
        test_task(1)
    def test02(self):
        test_task(2)
    def test03(self):
        test_task(3)
    def test04(self):
        test_task(4)
    def test05(self):
        test_task(5)
    def test06(self):
        test_task(6)
    def test07(self):
        test_task(7)
    def test08(self):
        test_task(8)
    def test09(self):
        test_task(9)
    def test10(self):
        test_task(10)
        
def action(suite): 
    t1 = unittest.runner.TextTestRunner() 
    t1.run(suite)



if __name__ == '__main__':
    task_pool = ThreadPool(10) #创建线程池
    t1 = unittest.TestLoader()
    suite = t1.loadTestsFromTestCase(TestTask) #获取测试用例
    requests = makeRequests(action, suite) #添加任务
        #执行任务
    for req in requests: 
        task_pool.putRequest(req) 
    task_pool.wait()  #等待执行
